package com.smbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smbms.dao.UserMapper;
import com.smbms.pojo.User;
import com.smbms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User login(String userCode, String userPassword) {

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userCode",userCode);

        User user = userMapper.selectOne(queryWrapper);

        if (user!=null){
            if (user.getUserPassword().equals(userPassword)){
                return user;
            }
        }
        return null;
    }

    @Override
    public IPage<User> getUserList(String userName, Integer userRole, Integer currPageNo, int pageSize) {
        //条件构造器
//        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
//
//        if (null!=userName){
//            queryWrapper.like("userName",userName);
//        }
//        if (userRole!=0){
//            queryWrapper.eq("userRole",userRole);
//        }

        Page<User> page = new Page<>(currPageNo,pageSize);

        IPage<User> iPage = userMapper.selectUserPage(page,userName,userRole);//userMapper.selectPage(page,queryWrapper);

        return iPage;
    }

}
